package saling_ticket.service;



public class SellingTicket_Lock implements  Runnable {

    private  int  ticket=55;
    Object lock = new Object();
    @Override
    public void run() {
        while(true){

                synchronized (lock){

                    if(ticket>0){
                        System.out.println(Thread.currentThread().getName() + "卖出了第" + ticket-- + "张票");//
                    }else{
                        break;
                    }
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
        }
    }
}
